<?php
/**
 * Created by 784855684@qq.com.
 * Link: https://github.com/lichtung/wshore
 * User: linzh
 * Date: 6/25/17
 * Time: 5:44 PM
 */
declare(strict_types=1);


namespace wshore\core;

/**
 * Class Midware 中间件
 * @package wshore\core
 */
abstract class Midware
{
    /**
     * 请求继续传递
     */
    const PROPAGATION_CONTINUE = 0;
    /**
     * 请求停止传递,立即结束脚本
     */
    const PROPAGATION_STOP = 1;
    /**
     * 请求终端,讲执行默认的流程
     */
    const PROPAGATION_BREAK = 2;

    protected $module = '';
    protected $controller = '';
    protected $action = '';
    protected $path = '';

    public function __construct(string $module, string $controller, string $action)
    {
        if ($module) {
            $this->module = $module ? str_replace('\\', '/', $module) : '';
            $this->path = $this->module ? $this->module . '/' : '';
        }
        $this->controller = $controller;
        $this->action = $action;
        $this->path .= $this->controller . '/' . $this->action;
    }

    /**
     * 中间件运行
     * @return int 返回的int值将影响该请求的进程,参照'PROPAGATION_CONTINUE','PROPAGATION_STOP','PROPAGATION_BREAK'的备注
     */
    abstract public function run(): int;


}